package widgets.Draw.Plotapi
{
	import flash.events.Event;
	import flash.events.EventDispatcher;

	public class EventBus extends EventDispatcher
	{
		private static var _eventBus:EventBus;
		private static var _lock:Boolean;

		public function EventBus()
		{
			if (!_lock)
				throw new Error("ContainerEventDispatcher can only defined once!");
		}

		public static function getInstance():EventBus
		{
			if (_eventBus == null)
			{
				_lock=true;
				_eventBus=new EventBus();
				_lock=false;
			}
			return _eventBus;
		}

		private function dispatch(type:String):Boolean
		{
			return this.dispatchEvent(new Event(type));
		}

		// 
		public static function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void
		{
			EventBus.getInstance().addEventListener(type, listener, useCapture, priority, useWeakReference);
		}

		public static function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void
		{
			EventBus.getInstance().removeEventListener(type, listener, useCapture);
		}

		public static function dispatch(type:String):Boolean
		{
			return EventBus.getInstance().dispatch(type);
		}

		public static function dispatchEvent(event:Event):Boolean
		{
			return EventBus.getInstance().dispatchEvent(event);
		}
	}
}